package Server;

import java.net.Socket;

/**
 * 
 * @author PZK
 *
 */
public class Client {

	private Listener listener;
	private Sender sender;

	private String SYSTEM_CODE = null;
	private String SYSTEM_REGEX = null;

	private String name = null;

	private boolean loggedIn = false;

	public Client(Socket mySocket, ClientHandler clientHandler) {

		this.listener = new Listener(clientHandler, mySocket, this);
		this.sender = new Sender(mySocket);

	}

	public void send(String message) {

		sender.send(message);

	}

	public void interrupt() {

		if (listener != null) {
			if (!listener.isInterrupted())
				listener.interrupt();
		}
		if (sender != null) {
			if (!sender.isInterrupted())
				sender.interrupt();
		}

	}

	public void setSystemCode(String code) {

		System.out.println(code);
		if (SYSTEM_CODE == null)
			SYSTEM_CODE = code;

	}

	public void setRegexCode(String code) {

		System.out.println(code);
		if (SYSTEM_REGEX == null)
			SYSTEM_REGEX = code;

	}

	public String getSystemCode() {

		return SYSTEM_CODE;

	}

	public String getRegexCode() {

		return SYSTEM_REGEX;

	}

	public void setName(String name) {

		this.name = name;
		this.loggedIn = true;

	}

	public String getName() {

		return name;

	}

	public boolean isLoggedIn() {

		return this.loggedIn;

	}

}
